/*     */ package com.zimbra.cs.datasource;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.Log.Level;
/*     */ import com.zimbra.common.util.LogFactory;
/*     */ import com.zimbra.cs.mailbox.Flag;
/*     */ import com.zimbra.cs.mailbox.Flag.FlagInfo;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.Message;
/*     */ import com.zimbra.cs.mailbox.OperationContext;
/*     */ import com.zimbra.cs.mailclient.imap.CAtom;
/*     */ import com.zimbra.cs.mailclient.imap.Flags;
/*     */ import java.util.Date;
/*     */ import javax.mail.MessagingException;
/*     */ import javax.mail.internet.MimeMessage;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public final class SyncUtil
/*     */ {
/*  35 */   private static final Flags EMPTY_FLAGS = new Flags();
/*     */   
/*     */ 
/*  38 */   private static int IMAP_FLAGS_BITMASK = Flag.BITMASK_REPLIED | Flag.BITMASK_DELETED | Flag.BITMASK_DRAFT | Flag.BITMASK_FLAGGED | Flag.BITMASK_UNREAD;
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static int imapToZimbraFlags(Flags flags)
/*     */   {
/*  46 */     int zflags = 0;
/*  47 */     if (flags.isAnswered()) zflags |= Flag.BITMASK_REPLIED;
/*  48 */     if (flags.isDeleted()) zflags |= Flag.BITMASK_DELETED;
/*  49 */     if (flags.isDraft()) zflags |= Flag.BITMASK_DRAFT;
/*  50 */     if (flags.isFlagged()) zflags |= Flag.BITMASK_FLAGGED;
/*  51 */     if (!flags.isSeen()) zflags |= Flag.BITMASK_UNREAD;
/*  52 */     return zflags;
/*     */   }
/*     */   
/*     */   public static Flags zimbraToImapFlags(int zflags) {
/*  56 */     return getFlagsToAdd(EMPTY_FLAGS, zflags);
/*     */   }
/*     */   
/*     */   public static int imapFlagsOnly(int zflags) {
/*  60 */     return zflags & IMAP_FLAGS_BITMASK;
/*     */   }
/*     */   
/*     */   public static Flags getFlagsToAdd(Flags flags, int zflags) {
/*  64 */     Flags toAdd = new Flags();
/*  65 */     if ((!flags.isAnswered()) && ((zflags & Flag.BITMASK_REPLIED) != 0)) {
/*  66 */       toAdd.set(CAtom.F_ANSWERED.atom());
/*     */     }
/*  68 */     if ((!flags.isDeleted()) && ((zflags & Flag.BITMASK_DELETED) != 0)) {
/*  69 */       toAdd.set(CAtom.F_DELETED.atom());
/*     */     }
/*  71 */     if ((!flags.isDraft()) && ((zflags & Flag.BITMASK_DRAFT) != 0)) {
/*  72 */       toAdd.set(CAtom.F_DRAFT.atom());
/*     */     }
/*  74 */     if ((!flags.isFlagged()) && ((zflags & Flag.BITMASK_FLAGGED) != 0)) {
/*  75 */       toAdd.set(CAtom.F_FLAGGED.atom());
/*     */     }
/*  77 */     if ((!flags.isSeen()) && ((zflags & Flag.BITMASK_UNREAD) == 0)) {
/*  78 */       toAdd.set(CAtom.F_SEEN.atom());
/*     */     }
/*  80 */     return toAdd;
/*     */   }
/*     */   
/*     */   public static Flags getFlagsToRemove(Flags flags, int zflags) {
/*  84 */     Flags toRemove = new Flags();
/*  85 */     if ((flags.isAnswered()) && ((zflags & Flag.BITMASK_REPLIED) == 0)) {
/*  86 */       toRemove.set(CAtom.F_ANSWERED.atom());
/*     */     }
/*  88 */     if ((flags.isDeleted()) && ((zflags & Flag.BITMASK_DELETED) == 0)) {
/*  89 */       toRemove.set(CAtom.F_DELETED.atom());
/*     */     }
/*  91 */     if ((flags.isDraft()) && ((zflags & Flag.BITMASK_DRAFT) == 0)) {
/*  92 */       toRemove.set(CAtom.F_DRAFT.atom());
/*     */     }
/*  94 */     if ((flags.isFlagged()) && ((zflags & Flag.BITMASK_FLAGGED) == 0)) {
/*  95 */       toRemove.set(CAtom.F_FLAGGED.atom());
/*     */     }
/*  97 */     if ((flags.isSeen()) && ((zflags & Flag.BITMASK_UNREAD) != 0)) {
/*  98 */       toRemove.set(CAtom.F_SEEN.atom());
/*     */     }
/* 100 */     return toRemove;
/*     */   }
/*     */   
/*     */   public static Date getInternalDate(Message msg, MimeMessage mm) {
/* 104 */     Date date = null;
/*     */     try {
/* 106 */       date = mm.getReceivedDate();
/*     */     }
/*     */     catch (MessagingException e) {}
/*     */     
/* 110 */     return date != null ? date : new Date(msg.getDate());
/*     */   }
/*     */   
/*     */   public static void setSyncEnabled(Mailbox mbox, int folderId, boolean enabled) throws ServiceException {
/* 114 */     mbox.alterTag(new OperationContext(mbox), folderId, MailItem.Type.FOLDER, Flag.FlagInfo.SYNC, enabled, null);
/*     */   }
/*     */   
/*     */   public static Log getTraceLogger(Log parent, String id) {
/* 118 */     String category = parent.getCategory();
/* 119 */     Log log = LogFactory.getLog(category + '.' + id + '.' + category);
/* 120 */     log.setLevel(Log.Level.trace);
/* 121 */     return log;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/datasource/SyncUtil.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */